package cn.tedu.util;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

//测试  HashMap实现类
public class Test5_1 {
    public static void main(String[] args) {
        //1.创建HashMap对象
        HashMap <Integer,String> map=new HashMap<>();
        //HashMap<key的类型，valuede类型> map=new HashMap<>();
        //2.调用方法
        map.put(928,"唐伯虎");
        map.put(927,"秋香");
        map.put(925,"如花");
        map.put(926,"石榴姐");
        map.put(920,"华夫人");
        //特点：数组无序+key不能相同，相同时value会被覆盖
        System.out.println(map);
        System.out.println(map.containsKey(928));
        System.out.println(map.containsValue("秋香"));
        System.out.println(map.equals("秋香"));
//        map.clear();
        System.out.println(map.get(927));
        System.out.println(map.hashCode());
        System.out.println(map.isEmpty());
        System.out.println(map.size());
        System.out.println(map.remove(920));


        //迭代Map集合里的数据
        Set<Integer> keySet= map.keySet();
        for (Integer k:keySet) {
            String v=map.get(k);
            if (v.equals("秋香")){
                System.out.println(v+",加个微信呗！");
            }
            System.out.println(k+"——>"+v);
        }
        //方式二：
        Collection<String> vs=map.values();
        for (String v:vs) {
            System.out.println("v=:"+v);
        }
        //方式三：
        Set<Map.Entry<Integer,String>> entrys =map.entrySet();
        for (Map.Entry<Integer,String> entry:entrys) {
            Integer k=entry.getKey();
            String v=entry.getValue();
            System.out.println(k+v);
        }
    }
}
